package com.sjr.easy.chat.config;

import com.sjr.easy.chat.dto.Result;
import com.sjr.easy.chat.exection.EasyChatException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception ex, HttpServletRequest request) {
        log.error("URI:{}, Method:{}", request.getRequestURI(), request.getMethod());
        log.error("ex:", ex);
        return Result.error();
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(EasyChatException.class)
    public Result<String> dynamicInfoExceptionHandler(EasyChatException ex, HttpServletRequest request) {
        log.error("URI:{}, Method:{}", request.getRequestURI(), request.getMethod());
        log.error("ex:", ex);
        return Result.error(ex.getCode(), ex.getMessage());
    }

}
